In [1]:
import sys
from glob import glob
import mkserialisable
mkserialisable.mk_netcdf()
import netCDF4
from mpl_toolkits.basemap import Basemap
import seasonalmean
data_dir = '/data/cmip5/output1/MOHC/HadGEM2-ES/rcp85/mon/atmos/' \
'Amon/r1i1p1/v20111215/tas/'
files = glob(data_dir + 'tas_Amon_HadGEM2-ES_rcp85_r1i1p1_*-*.nc')
# get variables for plotting
d = netCDF4.Dataset(files[0])
lon = d.variables['lon'][:]
lat = d.variables['lat'][:]
d.close()
In [101]:
y0 = 2010
y1 = 2200
m0 = 12
# time methods
for parallel in (False, True):
print ('parallel' if parallel else 'serial') + ':',
%timeit seasonalmean.run(files, 'tas', y0, m0, y1, parallel)
# check they give the same results
results_serial = seasonalmean.run(files, 'tas', y0, m0, y1, False)
results_parallel = seasonalmean.run(files, 'tas', y0, m0, y1, True)
print 'results equal:', (results_serial == results_parallel).all()
results = results_parallel
mn, mx = results.min(), results.max()
In [111]:
def plot (i):
tas = results[i]
m = Basemap(projection = 'merc', llcrnrlat = -80, urcrnrlat = 80,
llcrnrlon = lon[0], urcrnrlon = lon[-1], lat_ts = 0)
m.drawcoastlines()
x, y = m(*np.meshgrid(lon, lat))
m.contourf(x, y, tas, levels = range(mn, mx, int((mx - mn) / 50)))
m1 = m0 + 3 - 1
y = y0 + i
plt.title('{0}/{1} to {2}/{3}'.format(m0, y, m1 % 12, y + m1 / 12))
plt.colorbar()
In [124]:
n = 10
for i in xrange(0, len(results), int(float(len(results)) / (n - 1))):
# create a new figure so we don't plot everything on the same graph
figure()
plot(i) # uses the last created figure